package io.renren.modules.frt.controller;

import java.util.Arrays;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.mapper.EntityWrapper;

import io.renren.modules.frt.entity.BaseReport2Entity;
import io.renren.modules.frt.service.BaseReport2Service;
import io.renren.modules.frt.service.TaskUserService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 * 表2：林下经济示范基地调查表
 *
 * @author qibing.huang
 * @email abingtech@163.com
 * @date 2018-11-25 10:25:33
 */
@RestController
@RequestMapping("frt/basereport2")
public class BaseReport2Controller {
    @Autowired
    private BaseReport2Service baseReport2Service;
    @Autowired
    private TaskUserService taskUserService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("frt:basereport2:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = baseReport2Service.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{reportId}")
    public R info(@PathVariable("reportId") Long reportId){
        BaseReport2Entity baseReport2 = baseReport2Service.selectById(reportId);

        return R.ok().put("basereport2", baseReport2);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @Transactional
    public R save(@RequestBody BaseReport2Entity baseReport2){
    	if(baseReport2.getTaskUserId() == null) {
    		return R.error("task_user_id["+baseReport2.getTaskUserId()+"]参数错误");
    	}
		baseReport2Service.insert(baseReport2);
		
		taskUserService.onlineCallbackTaskUser(baseReport2.getTaskUserId(), baseReport2.getReportId());

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody BaseReport2Entity baseReport2){
		baseReport2Service.updateById(baseReport2);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("frt:basereport2:delete")
    public R delete(@RequestBody Long[] reportIds){
		baseReport2Service.deleteBatchIds(Arrays.asList(reportIds));

        return R.ok();
    }

}
